﻿// ActionScript file
/* 
	@绘制正多边形
	@numTips 		多边形的条数
	@innerRadius 	内圈的半�?
	@outerRadius  	外圈的半�?
	@roundAngle		便宜的角�?
 */
package org.nickro.graphics{
	public class Star extends Polygon{
		public function Star(numTips:uint,
							innerRadius:Number,
							outerRadius:Number,
							roundAngle:Number=0){
			super();
			setStar(numTips,innerRadius,outerRadius,roundAngle);
		}
		public function setStar(numTips:uint,
								innerRadius:Number,
								outerRadius:Number,
								roundAngle:Number):void{
			if(numTips >2){
				var centerX:Number=outerRadius;
				var centerY:Number=outerRadius;
				var dx:Number , dy:Number;
				var step:Number = (Math.PI*2)/numTips;
				var halfStep:Number=step/2;
				var xpoints:Array=new Array();
				var ypoints:Array=new Array();
				var startAngle:Number=(roundAngle*180)/Math.PI;
				for(var i:uint=0;i<numTips;i++){
					//起始点在左右中轴两端-->x（cos)控制端点，y(sin)控制方向
					//dx=centerX + Math.cos(startAngle+(step*i))*outerRadius;
					//dy=centerY + Math.sin(startAngle+(step*i))*outerRadius;
					//起始点在上下中轴两端-->x(sin)控制方向，y(cos)控制端点
					dx=centerX + Math.sin(startAngle+step*i)*outerRadius;
					dy=centerY - Math.cos(startAngle+step*i)*outerRadius;
					xpoints.push(dx);
					ypoints.push(dy);
					
					//dx=centerX + Math.cos(startAngle+((step*i) + halfStep))*innerRadius;
					//dy=centerY + Math.sin(startAngle+((step*i) + halfStep))*innerRadius;
					dx=centerX + Math.sin(startAngle+((step*i) + halfStep))*innerRadius;
					dy=centerY - Math.cos(startAngle+((step*i) + halfStep))*innerRadius;
					xpoints.push(dx);
					ypoints.push(dy);
				}
				setPoints(xpoints,ypoints);
			}
		}
	}
}